package cn.topkinson.rocketmq.seckill.service;

import cn.topkinson.rocketmq.seckill.common.RocketConstant;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.TransactionSendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;

/**
 * @Author huangzihao
 * @Date 2021/1/18 14:29
 */
@Slf4j
@Service
public class ProducerService {
    @Autowired
    private RocketMQTemplate rocketMQTemplate;
    public String sendTx(String topic,String message){
        //发送消息事务消息
        rocketMQTemplate.sendMessageInTransaction(RocketConstant.GROUP_ORDER_TX, topic, MessageBuilder.withPayload(message).build(), null);
        log.info("事务消息已发送：{}-{}",topic,message);
        return "OK";
    }
}
